package cn.doitedu.aviator;

import com.googlecode.aviator.AviatorEvaluator;
import com.googlecode.aviator.Expression;

import java.util.HashMap;


public class AviatorDemo {

    public static void main(String[] args) {

        // 常量表达式
        Expression expression = AviatorEvaluator.compile("1+2*10");
        Object result = expression.execute();

        System.out.println(result);


        // 变量表达式
        Expression exp = AviatorEvaluator.compile("a*(b-c)");
        HashMap<String, Object> param = new HashMap<>();
        param.put("a",10);
        param.put("b",40);
        param.put("c",30);

        Object res = exp.execute(param);
        System.out.println(res);



        // 变量表达式2
        Expression exp2 = AviatorEvaluator.compile("a>b?a:c");
        HashMap<String, Object> param2 = new HashMap<>();
        param2.put("a",10);
        param2.put("b",40);
        param2.put("c",30);

        Object res2 = exp2.execute(param2);
        System.out.println(res2);

    }


}
